import { defineStore } from "pinia";

interface ICounterState {
  count: number;
}

export const useCounterStore = defineStore("counter", {
  state: (): ICounterState => {
    return {
      count: 0,
    };
  },
  getters: {
    oddOrEven(state) {
      // return state.count % 2 === 0 ? '偶数' : '奇数'
      return (state.count & 1) === 0 ? "偶数" : "奇数";
    },
  },
  actions: {
    // 接受n个参数
    increment() {
      setTimeout(() => {
        this.count++;
      }, 1000)
    },
  },
});
